package com.showcai.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.showcai.dao.AdminUserMapper;
import com.showcai.dao.ApplyWatchMapper;
import com.showcai.dao.OrderMapper;
import com.showcai.dao.RefundApplyMapper;
import com.showcai.module.AdminUser;
import com.showcai.module.ApplyWatch;
import com.showcai.module.BaseModule;
import com.showcai.module.RefundApply;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.service.AdminUserService;
import com.showcai.service.OrderService;
import com.showcai.service.RefundApplyService;
import com.showcai.service.ServiceBase;
import com.showcai.util.MD5Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RefundApplyServiceImpl extends ServiceBase implements RefundApplyService {

    @Autowired
    RefundApplyMapper refundApplyMapper;
    @Autowired
    ApplyWatchMapper applyWatchMapper;

    @Override
    public ApplyWatch selectRefundApply(Long orderId) {
        return applyWatchMapper.selectApplyByOrderId(orderId);

    }

    @Override
    public void addRefundApply(RefundApply refundApply) {
        refundApply.setCreateTime(new Date());
        refundApply.setStatus(OrderService.REFUND);
        refundApplyMapper.addRefundApply(refundApply);
    }

    @Override
    public PageInfo selectRefundApplyPageList(Map<String, String> map) {
        PageHelper.startPage(Integer.parseInt(map.get("page")),Integer.parseInt(map.get("pageSize")));
        List <RefundApply> list = refundApplyMapper.selectRefundApplyList(map);
        PageInfo pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<RefundApply> selectRefundApplyList(Map<String, String> map) {
        return refundApplyMapper.selectRefundApplyList(map);
    }

    @Override
    public void agreeRefundApply(Long orderId,Byte status) {
        Map map = new HashMap<String,String>();
        map.put("orderId",String.valueOf(orderId));
        map.put("status",String.valueOf(status));
        refundApplyMapper.agreeRefundApply(map);
    }
}
